#include"process.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define NUM 101
#define STYLE '='
#define POINT '.'
#define SPACE ' '
const int pnum = 3;
//version 2
void FlushProcess(double total, double current)
{
  double rate = (current/total)*100;
  //printf("test:%.1lf%%\r",rate);
  //fflush(stdout);
  char bar[NUM];//百分之1对应一个=
  memset(bar,'\0',sizeof(bar));
  for(int i = 0;i < (int)rate;i++)
  {
    bar[i] = STYLE;
  }
 static int num = 0;
 ++num;
 num %=pnum;
  char points[pnum+1];
  memset(points,'\0',sizeof(points));
  for(int m = 0;m < pnum;m++)
  {
    if(m < num) points[m] = POINT;
    else points[m] = SPACE; 
  }
  printf("[%-100s][%.1lf%%]%s\r", bar,rate,points);
  fflush(stdout);
}

//version 1
//void Process()
//{
//  const char *lable = "|/-\\";
//  int len = strlen(lable);
//  char bar[NUM];
//  memset(bar,'\0',sizeof(bar));
//  int cnt = 0;
//  while(cnt <= 100)
//  {
//    printf("[%-100s][%d%%][%c]\r",bar,cnt,lable[cnt%len]);
//    fflush(stdout);
//    bar[cnt] = STYLE;
//    ++cnt;
//
//    usleep(50000);
//  }
//  printf("\r\n");
//}
